package com.pureut.system.controller;

import java.util.Arrays;
import java.util.List;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.system.domain.SampleRequest;
import com.pureut.system.domain.vo.MaterialCertificationApplicationVo;
import com.pureut.system.domain.vo.SampleRequestVo;
import com.pureut.system.service.ISampleRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: pureut
 * @Date: 2024-12-04 15:44:26
 * @Desc: 样品申请Controller
 */
@RestController
@RequestMapping("/sample/request")
public class SampleRequestController extends BaseController {

    /**
     * 样品申请Service
     */
    @Resource
    private ISampleRequestService sampleRequestService;

    /**
     * 查询样品申请列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("sampleRequest-list")
    @GetMapping("/list")
    public TableDataInfo list(SampleRequestVo sampleRequestVo) {
        startPage();
        return getDataTable(sampleRequestService.queryPage(sampleRequestVo));

    }

    /**
     * 获取样品申请详细信息
     * @param: id 样品申请主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("sampleRequest-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sampleRequestService.getInfoById(id));
    }

    /**
     * 新增样品申请
     * @param: sampleRequest 样品申请对象
     * @return: Json工具类对象
     */
    @Log(title = "新增样品申请", businessType = BusinessType.INSERT)
    //    @SaCheckPermission("sampleRequest-add")
    @PostMapping
    public AjaxResult add( @RequestBody SampleRequestVo sampleRequestVo) {
        return toAjax(sampleRequestService.save(sampleRequestVo));
    }

    /**
     * 修改样品申请
     * @param: sampleRequest 样品申请对象
     * @return: Json工具类对象
     */
    @Log(title = "修改样品申请", businessType = BusinessType.UPDATE)
    //    @SaCheckPermission("sampleRequest-edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SampleRequestVo sampleRequestVo) {
        return toAjax(sampleRequestService.updateById(sampleRequestVo));
    }

    /**
     * 删除样品申请
     * @param: id 样品申请主键
     * @return: Json工具类对象
     */
    @Log(title = "删除样品申请", businessType = BusinessType.DELETE)
    //    @SaCheckPermission("sampleRequest-remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sampleRequestService.removeByIds(Arrays.asList(ids)));
    }

    /**
     * 获取样品申请 初始化信息
     * @param: id 样品申请主键
     * @return: Json工具类对象
     */
    @GetMapping(value = "/infoInit")
    public AjaxResult infoInit() {
        return AjaxResult.success(sampleRequestService.infoInit());
    }

    /**
     * 审核
     * @param: id 样品申请主键
     * @return: Json工具类对象
     */
    @PostMapping(value = "/examine")
    public AjaxResult examine(@RequestBody MaterialCertificationApplicationVo materialCertificationApplicationVo) {
        return toAjax(sampleRequestService.examine(materialCertificationApplicationVo));
    }
}
